integer

type integer

A 64-bit signed integer type, ranging from -2^63 to (2^63)-1, supporting a standard complement of numerical operations.

Since

0.6.0

Constructors

Link copied to clipboard
pure constructor(value: text, [radix: integer])

Construct an integer object by parsing a signed text representation of an integer.

Base prefixes are not supported, so one must write e.g. integer('CAFE', 16) rather than integer('0xCAFE').

Case is ignored, i.e. integer('CAFE', 16) and integer('cafe', 16) are equivalent.

Supported radixes are from 2 to 36 (inclusive).

pure constructor(value: decimal)

Construct an integer from a decimal, with any fractional part truncated (i.e. rounding toward 0).

Properties

Link copied to clipboard
val MAX_VALUE: integer = 9223372036854775807

The maximum value an integer can have, (2^63)-1, or 9223372036854775807.

Link copied to clipboard
val MIN_VALUE: integer = -9223372036854775808

The minimum value an integer can have, -2^63, or -9223372036854775808.

Functions

Link copied to clipboard
pure function abs(): integer

Returns the absolute value of this integer; i.e. the integer itself if it's positive or its negation if it's negative.

Link copied to clipboard
pure static function from_hex(value: text): integer

Parse an unsigned hexadecimal text representation of an integer.

Base prefixes are not supported, so one must write e.g. integer.from_hex('CAFE') rather than integer.from_hex('0xCAFE').

Case is ignored, i.e. integer.from_hex('CAFE') and integer.from_hex('cafe') are equivalent.

Link copied to clipboard
pure static function from_text(value: text, [radix: integer]): integer

Parse a signed text representation of an integer.

Link copied to clipboard
(alias) pure function hex(): text

Convert this integer to hexadecimal text.

Does not include a base prefix in the output, i.e. integer(25).to_hex() returns 19 rather than 0x19.

Alias
Link copied to clipboard
pure function max(value: big_integer): big_integer

Returns the greater of this integer and a big_integer value; i.e. value if value is greater than this integer, or this integer otherwise.

pure function max(value: decimal): decimal

Returns the greater of this integer and a decimal value; i.e. value if value is greater than this integer, or this integer otherwise.

pure function max(value: integer): integer

Returns the greater of this integer and another integer value; i.e. value if value is greater than this integer, or this integer otherwise.

Link copied to clipboard
pure function min(value: big_integer): big_integer

Returns the lesser of this integer and a big_integer value; i.e. value if value is less than this integer, or this integer otherwise.

pure function min(value: decimal): decimal

Returns the lesser of this integer and a decimal value; i.e. value if value is less than this integer, or this integer otherwise.

pure function min(value: integer): integer

Returns the lesser of this integer and another integer value; i.e. value if value is less than this integer, or this integer otherwise.

Link copied to clipboard
(alias) pure static function parseHex(value: text): integer

Parse an unsigned hexadecimal text representation of an integer.

Base prefixes are not supported, so one must write e.g. integer.from_hex('CAFE') rather than integer.from_hex('0xCAFE').

Case is ignored, i.e. integer.from_hex('CAFE') and integer.from_hex('cafe') are equivalent.

Alias
Link copied to clipboard
pure function pow(exponent: integer): integer

Raise this integer to the power of the given exponent. SQL compatible.

Fails on integer overflow; so if results outside integer range are expected, first convert to big_integer (e.g. with integer.to_big_integer() or big_integer(integer)) and then use big_integer.pow().

Note that:

  • the exponent cannot be negative

  • if the exponent is 0, the result is 1

  • if the exponent is 1, the result is the original value

Link copied to clipboard
pure function sign(): integer

Returns the sign of the integer: -1 if negative, 0 if zero, and 1 if positive.

It holds that for all x, x == x.sign() * x.abs().

Link copied to clipboard
(alias) pure function signum(): integer

Returns the sign of the integer: -1 if negative, 0 if zero, and 1 if positive.

It holds that for all x, x == x.sign() * x.abs().

Alias
Link copied to clipboard
(alias) pure function str(): text

Convert this integer to a base-10 text representation.

Alias
(alias) pure function str(radix: integer): text

Convert this integer to a text representation with the specified radix.

Does not include a base prefix in the output, i.e. integer(25).to_text(16) returns 19 rather than 0x19.

Supported radixes are from 2 to 36 (inclusive).

Alias
Link copied to clipboard
pure function to_big_integer(): big_integer

Convert this integer to a big integer.

Link copied to clipboard
pure function to_decimal(): decimal

Convert this integer to a decimal.

Link copied to clipboard
pure function to_hex(): text

Convert this integer to hexadecimal text.

Does not include a base prefix in the output, i.e. integer(25).to_hex() returns 19 rather than 0x19.

Link copied to clipboard
pure function to_text(): text

Convert this integer to a base-10 text representation.

pure function to_text(radix: integer): text

Convert this integer to a text representation with the specified radix.

Does not include a base prefix in the output, i.e. integer(25).to_text(16) returns 19 rather than 0x19.

Supported radixes are from 2 to 36 (inclusive).